package com.dtease.agent.sse.server.controller;

import com.dtease.agent.sse.server.model.EventMessage;
import com.dtease.agent.sse.server.service.SseService;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

/**
* @description 推送控制器
* @author chentl
* @class PushController
* @package com.dtease.agent.sse.server.controller
* @since 2025/5/4 08:37
*/
@RestController
@RequestMapping("/push")
public class PushController {

    @Resource
    private SseService sseService;

    @PostMapping("/to")
    public Mono<Void> push(@RequestParam String sessionId, @RequestBody EventMessage message) {
        // todo 这里可以接收到消息之后  保存 ai 回复的消息。

        Mono<Void> mono = Mono.just(message)
                .doOnNext(msg -> {
                    // 处理消息发送逻辑
                    sseService.enqueueMessage(sessionId, msg);
                })
                .then();
        return mono;
    }
}